package serviceset1

import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification

import java.text.SimpleDateFormat

class CustomerSpec extends Specification implements DomainUnitTest<Customer> {

    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd")

    def setup() {
    }

    def cleanup() {
    }

    void "test a valid properties"() {
        given:
        def params = [name: "marsdonne", gender: 1, birthday: dateFormat.parse("19700203")]

        when:
        def customerInstance = new Customer(params)
        customerInstance.save()

        then:
        !customerInstance.hasErrors()
    }

    void "test an invalid properties"() {
        given:
        def params = [name: "124123421", gender: 2, birthday: dateFormat.parse( "20200203")]

        when:
        def customerInstance = new Customer(params)
        customerInstance.save()

        then:
        customerInstance.hasErrors()
        customerInstance.errors.allErrors.size() == 3
    }
}
